﻿/*
 Pre-Deployment Script Template							
--------------------------------------------------------------------------------------
 This file contains SQL statements that will be executed before the build script.	
 Use SQLCMD syntax to include a file in the pre-deployment script.			
 Example:      :r .\myfile.sql								
 Use SQLCMD syntax to reference a variable in the pre-deployment script.		
 Example:      :setvar TableName MyTable							
               SELECT * FROM [$(TableName)]					
--------------------------------------------------------------------------------------
*/

--USE [master]
--GO

--/****** Object:  Database [$(DatabaseName)]    Script Date: 09/23/2014 21:26:55 ******/
--IF  EXISTS (SELECT name FROM sys.databases WHERE name = N'Hogar')
--DROP DATABASE [$(DatabaseName)]
--GO

--USE [master]
--GO

--DECLARE @InstancePath NVARCHAR(max)
--DECLARE @HogarFileName NVARCHAR(max)
--DECLARE @HogarLogFileName NVARCHAR(max)
--DECLARE @SQLQuery NVARCHAR(max)

--SELECT @InstancePath = SUBSTRING(physical_name, 1, CHARINDEX(N'master.mdf', LOWER(physical_name)) - 1)
--                  FROM master.sys.master_files
--                  WHERE database_id = 1 AND file_id = 1
                  
--SET @HogarFileName = @InstancePath + 'Hogar.mdf'
--SET @HogarLogFileName = @InstancePath + 'Hogar_log.ldf'

--/****** Object:  Database [$(DatabaseName)]    Script Date: 09/23/2014 21:26:55 ******/

--SET @SQLQuery = N'CREATE DATABASE [$(DatabaseName)] ON  PRIMARY 
--( NAME = N''Hogar'', FILENAME = N''' + @HogarFileName + ''' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
-- LOG ON 
--( NAME = N''Hogar_log'', FILENAME = N''' + @HogarLogFileName + ''' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)'


--EXEC (@SQLQuery)

--ALTER DATABASE [$(DatabaseName)] SET COMPATIBILITY_LEVEL = 100
--GO

--IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
--begin
--EXEC [$(DatabaseName)].[dbo].[sp_fulltext_database] @action = 'enable'
--end
--GO

ALTER DATABASE [$(DatabaseName)] SET ANSI_NULL_DEFAULT ON 
GO

ALTER DATABASE [$(DatabaseName)] SET ANSI_NULLS ON 
GO

ALTER DATABASE [$(DatabaseName)] SET ANSI_PADDING ON 
GO

ALTER DATABASE [$(DatabaseName)] SET ANSI_WARNINGS ON 
GO

ALTER DATABASE [$(DatabaseName)] SET ARITHABORT ON 
GO

ALTER DATABASE [$(DatabaseName)] SET AUTO_CLOSE OFF 
GO

ALTER DATABASE [$(DatabaseName)] SET AUTO_CREATE_STATISTICS ON 
GO

ALTER DATABASE [$(DatabaseName)] SET AUTO_SHRINK OFF 
GO

ALTER DATABASE [$(DatabaseName)] SET AUTO_UPDATE_STATISTICS ON 
GO

ALTER DATABASE [$(DatabaseName)] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO

ALTER DATABASE [$(DatabaseName)] SET CURSOR_DEFAULT  LOCAL 
GO

ALTER DATABASE [$(DatabaseName)] SET CONCAT_NULL_YIELDS_NULL ON 
GO

ALTER DATABASE [$(DatabaseName)] SET NUMERIC_ROUNDABORT OFF 
GO

ALTER DATABASE [$(DatabaseName)] SET QUOTED_IDENTIFIER ON 
GO

ALTER DATABASE [$(DatabaseName)] SET RECURSIVE_TRIGGERS OFF 
GO

ALTER DATABASE [$(DatabaseName)] SET  DISABLE_BROKER 
GO

ALTER DATABASE [$(DatabaseName)] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO

ALTER DATABASE [$(DatabaseName)] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO

ALTER DATABASE [$(DatabaseName)] SET TRUSTWORTHY OFF 
GO

ALTER DATABASE [$(DatabaseName)] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO

ALTER DATABASE [$(DatabaseName)] SET PARAMETERIZATION SIMPLE 
GO

ALTER DATABASE [$(DatabaseName)] SET READ_COMMITTED_SNAPSHOT OFF 
GO

ALTER DATABASE [$(DatabaseName)] SET HONOR_BROKER_PRIORITY OFF 
GO

ALTER DATABASE [$(DatabaseName)] SET  READ_WRITE 
GO

ALTER DATABASE [$(DatabaseName)] SET RECOVERY FULL 
GO

ALTER DATABASE [$(DatabaseName)] SET  MULTI_USER 
GO

ALTER DATABASE [$(DatabaseName)] SET PAGE_VERIFY NONE  
GO

ALTER DATABASE [$(DatabaseName)] SET DB_CHAINING OFF 
GO


/****** Object:  Login [$(DatabaseName)]    Script Date: 09/23/2014 21:27:18 ******/
--IF  EXISTS (SELECT * FROM sys.server_principals WHERE name = N'Hogar')
--DROP LOGIN [Hogar]
--GO

/* For security reasons the login is created disabled and with a random password. */
/****** Object:  Login [$(DatabaseName)]    Script Date: 09/23/2014 21:27:18 ******/
IF NOT EXISTS (SELECT * FROM sys.server_principals WHERE name = N'Hogar')
BEGIN
	CREATE LOGIN [Hogar] WITH PASSWORD=N'hogar', DEFAULT_DATABASE=[$(DatabaseName)], DEFAULT_LANGUAGE=[Español], CHECK_EXPIRATION=OFF, CHECK_POLICY=ON
END
GO

EXEC sys.sp_addsrvrolemember @loginame = N'Hogar', @rolename = N'sysadmin'
GO

EXEC sys.sp_addsrvrolemember @loginame = N'Hogar', @rolename = N'dbcreator'
GO
